/**
 * 神州信息(2012)
 */
package net.abbp.report.model.io.impl;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import net.abbp.core.transform.xml.jaxb.ColorAdapter;
import net.abbp.core.util.BooleanUtils;
import net.abbp.core.util.NumberUtils;
import net.abbp.core.util.StringUtils;
import net.abbp.report.model.Cell;
import net.abbp.report.model.InfoObject;
import net.abbp.report.model.ReportModel;
import net.abbp.report.model.cell.style.BorderStyle;
import net.abbp.report.model.cell.style.FontStyle;
import net.abbp.report.model.cell.style.HorizentalAlignment;
import net.abbp.report.model.cell.style.Style;
import net.abbp.report.model.cell.style.TextStyle;
import net.abbp.report.model.cell.style.VerticalAlignment;
import net.abbp.report.model.headerfooter.HFElement;
import net.abbp.report.model.headerfooter.ReportHF;
import net.abbp.report.model.io.IModelIO;
import net.abbp.report.model.io.IValueIO;
import net.abbp.report.model.io.ValueIOManager;
import net.abbp.report.utils.ColorUtils;
import net.abbp.report.utils.Dom4jUtils;

import org.dom4j.Document;
import org.dom4j.Element;

import com.reportgear.report.model.auxiliary.ColumnPropList;
import com.reportgear.report.model.auxiliary.ColumnProperty;
import com.reportgear.report.model.auxiliary.ColumnType;
import com.reportgear.report.model.auxiliary.RowPropList;
import com.reportgear.report.model.auxiliary.RowProperty;
import com.reportgear.report.model.auxiliary.RowType;
import com.reportgear.report.print.Margin;
import com.reportgear.report.print.PaperSize;
import com.reportgear.report.setting.PaperSetting;
import com.reportgear.report.setting.ReportSettings;

/**
 * 模型XML序列化
 * 
 * @version 1.0
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since ABBP 1.0
 * 
 *        <pre>
 * 历史：
 *      建立: Jul 28, 2012 lexloo
 * </pre>
 */
public class ModelXmlIO implements IModelIO {

    @Override
    public String write(ReportModel model) {
        Document document = Dom4jUtils.createDocument();
        Element root = document.addElement("ReportModel");
        root.addAttribute("Version", model.getVersion());

        this.createInfoObj(root, model.getInfoObject());
        Map<Style, String> styleMap = this.createStyleMap(model);
        this.createStyles(root, styleMap);
        this.createCPL(root, model.getColumnPropList());
        this.createRPL(root, model.getRowPropList());
        this.createRS(root, model.getReportSettings());
        this.createCells(root, model.getCellIterator(), styleMap);

        return document.asXML();
    }

    @Override
    public ReportModel read(String value) {
        Document document = Dom4jUtils.createDocument(value);
        Element root = document.getRootElement();

        String version = root.attributeValue("Version");
        ReportModel model = new ReportModel();
        if (model.getVersion() != version) {
            // 版本不对
        }

        this.readInfoObj(root, model);
        this.readCPL(root, model);
        this.readRPL(root, model);
        this.readRS(root, model);
        Map<String, Style> stylesMap = this.readStyle(root);
        this.readCells(root, stylesMap, model);

        return model;
    }

    /**
     * 写入基本对象
     * 
     * @param root 根节点
     * @param infoObject 基本对象
     */
    private void createInfoObj(Element root, InfoObject infoObject) {
        if (infoObject != null) {
            Element elInfo = root.addElement("Info");
            elInfo.addAttribute("Clazz", infoObject.getClass().getName());
            
            ValueIOManager ioManager = ValueIOManager.INSTANCE;

            IValueIO io = ioManager.getValueIO(infoObject.getClass());

            io.write(elInfo, infoObject);
        }
    }

    /**
     * 创建样式
     * 
     * @param root 根节点
     * @param styleMap 样式Map
     */
    private void createStyles(Element root, Map<Style, String> styleMap) {
        Element elStyles = root.addElement("Styles");

        for (Map.Entry<Style, String> entry : styleMap.entrySet()) {
            Element elStyle = elStyles.addElement("Style");
            elStyle.addAttribute("Name", entry.getValue());

            Style style = entry.getKey();
            elStyle.addElement("TextStyle").addText(style.getTextStyle().name());
            elStyle.addElement("HorizentalAlignment").addText(style.getHorizentalAlignment().name());
            elStyle.addElement("VerticalAlignment").addText(style.getVerticalAlignment().name());

            Element elBorder = elStyle.addElement("BorderStyle");
            BorderStyle borderStyle = style.getBorderStyle();
            elBorder.addAttribute("BottomColor", ColorUtils.toHexEncoding(borderStyle.getBottomColor()));
            elBorder.addAttribute("BottomStyle", StringUtils.convertToString(borderStyle.getBottomStyle()));
            elBorder.addAttribute("HoriColor", ColorUtils.toHexEncoding(borderStyle.getHorizentalColor()));
            elBorder.addAttribute("HoriStyle", StringUtils.convertToString(borderStyle.getHorizentalStyle()));
            elBorder.addAttribute("LeftColor", ColorUtils.toHexEncoding(borderStyle.getLeftColor()));
            elBorder.addAttribute("LeftStyle", StringUtils.convertToString(borderStyle.getLeftStyle()));
            elBorder.addAttribute("RightColor", ColorUtils.toHexEncoding(borderStyle.getRightColor()));
            elBorder.addAttribute("RightStyle", StringUtils.convertToString(borderStyle.getRightStyle()));
            elBorder.addAttribute("TopColor", ColorUtils.toHexEncoding(borderStyle.getTopColor()));
            elBorder.addAttribute("TopStyle", StringUtils.convertToString(borderStyle.getTopStyle()));
            elBorder.addAttribute("VertColor", ColorUtils.toHexEncoding(borderStyle.getVerticalColor()));
            elBorder.addAttribute("VertStyle", StringUtils.convertToString(borderStyle.getVerticalStyle()));

            Element elFont = elStyle.addElement("FontStyle");
            FontStyle fontStyle = style.getFontStyle();
            elFont.addAttribute("Name", fontStyle.getName());
            elFont.addAttribute("Style", StringUtils.convertToString(fontStyle.getStyle(), "0"));
            elFont.addAttribute("Size", StringUtils.convertToString(fontStyle.getSize(), "12"));
            elFont.addAttribute("Foreground", ColorAdapter.toHexEncoding(fontStyle.getForeground()));
            elFont.addAttribute("Shadow", StringUtils.convertToString(fontStyle.isShadow(), "false"));
            elFont.addAttribute("Strikethrough", StringUtils.convertToString(fontStyle.isStrikethrough(), "false"));
            elFont.addAttribute("Subscript", StringUtils.convertToString(fontStyle.isSubscript(), "false"));
            elFont.addAttribute("Superscript", StringUtils.convertToString(fontStyle.isSuperscript(), "false"));
            elFont.addAttribute("Underline", StringUtils.convertToString(fontStyle.getUnderline(), ""));

            Element elFormat = elStyle.addElement("Format").addText(style.getFormatterKey());
        }
    }

    /**
     * 创建所有的StyleMap，用于单元格保存样式
     * 
     * @param model 当前模型
     * @return Style 演示
     */
    private Map<Style, String> createStyleMap(ReportModel model) {
        Map<Style, String> rtn = new HashMap<Style, String>();

        // 直接从单元格获取，避免重复的样式
        int ptr = 1;
        for (Iterator<Cell> itr = model.getCellIterator(); itr.hasNext();) {
            Cell cell = itr.next();

            Style style = cell.getStyle();
            if (style != null) {
                if (!rtn.containsKey(style)) {
                    rtn.put(style, "Style" + (ptr++));
                }
            }
        }

        return rtn;
    }

    /**
     * 序列化列信息
     * 
     * @param root 根节点
     * @param columnPropList 模型列配置
     * @return 序列化节点
     */
    private void createCPL(Element root, ColumnPropList columnPropList) {
        Element rtn = root.addElement("CPL");

        for (ColumnProperty prop : columnPropList.getAllElements()) {
            Element el = rtn.addElement("Prop");

            el.addAttribute("Width", StringUtils.convertToString(prop.getWidth()));
            el.addAttribute("Visible", StringUtils.convertToString(prop.isVisible()));
            el.addAttribute("Group", StringUtils.convertToString(prop.isGroup()));
            el.addAttribute("Type", StringUtils.convertToString(prop.getType()));
        }
    }

    /**
     * 序列化列信息
     * 
     * @param root 根节点
     * @param rowPropList 模型行配置
     * @return 序列化节点
     */
    private void createRPL(Element root, RowPropList rowPropList) {
        Element rtn = root.addElement("RPL");

        for (RowProperty prop : rowPropList.getAllElements()) {
            Element el = rtn.addElement("Prop");

            el.addAttribute("Height", StringUtils.convertToString(prop.getHeight()));
            el.addAttribute("Visible", StringUtils.convertToString(prop.isVisible()));
            el.addAttribute("Group", StringUtils.convertToString(prop.isGroup()));
            el.addAttribute("Type", StringUtils.convertToString(prop.getType()));
        }
    }

    /**
     * 序列化报表设置
     * 
     * @param root 根节点
     * @param reportSettings 报表设置
     */
    private void createRS(Element root, ReportSettings reportSettings) {
        ValueIOManager ioManager = ValueIOManager.INSTANCE;
        Element rtn = root.addElement("ReportSettings");

        PaperSetting paperSetting = reportSettings.getPaperSetting();
        Element elPaperSetting = rtn.addElement("PaperSetting");

        PaperSize pageSize = paperSetting.getPaperSize();
        Element elPageSize = elPaperSetting.addElement("PaperSize");
        elPageSize.addAttribute("Width", StringUtils.convertToString(pageSize.getWidth()));
        elPageSize.addAttribute("Height", StringUtils.convertToString(pageSize.getHeight()));
        elPageSize.addAttribute("Caption", pageSize.getCaption());

        Margin margin = paperSetting.getMargin();
        Element elMargin = elPaperSetting.addElement("Margin");
        elMargin.addAttribute("Top", StringUtils.convertToString(margin.getTop()));
        elMargin.addAttribute("Left", StringUtils.convertToString(margin.getLeft()));
        elMargin.addAttribute("Bottom", StringUtils.convertToString(margin.getBottom()));
        elMargin.addAttribute("Right", StringUtils.convertToString(margin.getRight()));

        Element elOrient = elPaperSetting.addElement("Orientation");
        elOrient.addText(StringUtils.convertToString(paperSetting.getOrientation()));

        // 表头
        {
            ReportHF header = reportSettings.getHeader();
            Element elHeader = rtn.addElement("Header");
            elHeader.addAttribute("Height", StringUtils.convertToString(header.getHeight()));

            List<HFElement> lst = header.getLeftList();
            Element elList = elHeader.addElement("Left");
            for (HFElement hf : lst) {
                Element elValue = elList.addElement("Item");
                elValue.addAttribute("Clazz", hf.getClass().getName());

                IValueIO io = ioManager.getValueIO(hf.getClass());
                io.write(elValue, hf);
            }

            lst = header.getCenterList();
            elList = elHeader.addElement("Center");
            for (HFElement hf : lst) {
                Element elValue = elList.addElement("Item");
                elValue.addAttribute("Clazz", hf.getClass().getName());

                IValueIO io = ioManager.getValueIO(hf.getClass());
                io.write(elValue, hf);
            }

            lst = header.getRightList();
            elList = elHeader.addElement("Right");
            for (HFElement hf : lst) {
                Element elValue = elList.addElement("Item");
                elValue.addAttribute("Clazz", hf.getClass().getName());

                IValueIO io = ioManager.getValueIO(hf.getClass());
                io.write(elValue, hf);
            }
        }

        {
            ReportHF footer = reportSettings.getFooter();
            Element elFooter = rtn.addElement("Footer");
            elFooter.addAttribute("Height", StringUtils.convertToString(footer.getHeight()));

            List<HFElement> lst = footer.getLeftList();
            Element elList = elFooter.addElement("Left");
            for (HFElement hf : lst) {
                Element elValue = elList.addElement("Item");
                elValue.addAttribute("Clazz", hf.getClass().getName());

                IValueIO io = ioManager.getValueIO(hf.getClass());
                io.write(elValue, hf);
            }

            lst = footer.getCenterList();
            elList = elFooter.addElement("Center");
            for (HFElement hf : lst) {
                Element elValue = elList.addElement("Item");
                elValue.addAttribute("Clazz", hf.getClass().getName());

                IValueIO io = ioManager.getValueIO(hf.getClass());
                io.write(elValue, hf);
            }

            lst = footer.getRightList();
            elList = elFooter.addElement("Right");
            for (HFElement hf : lst) {
                Element elValue = elList.addElement("Item");
                elValue.addAttribute("Clazz", hf.getClass().getName());

                IValueIO io = ioManager.getValueIO(hf.getClass());
                io.write(elValue, hf);
            }
        }
    }

    /**
     * 序列化所有单元格
     * 
     * @param root 根节点
     * @param cellIterator 所有单元格
     * @param styleMap 样式Map
     */
    private void createCells(Element root, Iterator<Cell> cellIterator, Map<Style, String> styleMap) {
        Element rtn = root.addElement("Cells");
        ValueIOManager ioManager = ValueIOManager.INSTANCE;

        for (Iterator<Cell> itr = cellIterator; itr.hasNext();) {
            Cell cell = itr.next();

            Element el = rtn.addElement("Cell");
            el.addAttribute("C", StringUtils.convertToString(cell.getColumn()));
            el.addAttribute("R", StringUtils.convertToString(cell.getRow()));
            el.addAttribute("CS", StringUtils.convertToString(cell.getColumnSpan()));
            el.addAttribute("RS", StringUtils.convertToString(cell.getRowSpan()));
            el.addAttribute("Style", styleMap.get(cell.getStyle()));

            // 输出对象
            Object value = cell.getValue();
            if (value != null) {
                Element elValue = el.addElement("Value");
                elValue.addAttribute("Clazz", value.getClass().getName());

                IValueIO io = ioManager.getValueIO(value.getClass());
                io.write(elValue, value);
            }
        }
    }

    /**
     * 读入所有单元格
     * 
     * @param root 根节点
     * @param stylesMap 样式查找
     * @param model 模型
     */
    @SuppressWarnings("unchecked")
    private void readCells(Element root, Map<String, Style> stylesMap, ReportModel model) {
        ValueIOManager ioManager = ValueIOManager.INSTANCE;

        Element el = root.element("Cells");
        List<Element> cells = el.elements("Cell");
        for (Element c : cells) {
            Cell cell = new Cell(NumberUtils.convertToInteger(c.attributeValue("C")), NumberUtils.convertToInteger(c
                    .attributeValue("R")));
            cell.setColumnSpan(NumberUtils.convertToInteger(c.attributeValue("CS")));
            cell.setRowSpan(NumberUtils.convertToInteger(c.attributeValue("RS")));
            cell.setStyle(stylesMap.get(c.attributeValue("Style")));

            Element elValue = c.element("Value");
            if (elValue != null) {
                IValueIO io = ioManager.getValueIO(elValue.attributeValue("Clazz"));
                cell.setValue(io.read(c.element("Value")));
            }

            model.addCell(cell);
        }
    }

    /**
     * 读入基本对象信息
     * 
     * @param root 根节点
     * @param model 模型对象
     */
    private void readInfoObj(Element root, ReportModel model) {
        Element el = root.element("Info");
        if (el != null) {
            ValueIOManager ioManager = ValueIOManager.INSTANCE;
            String clazz = el.attributeValue("Clazz");
            IValueIO io = ioManager.getValueIO(clazz);

            model.setInfoObject((InfoObject) io.read(el));
        }
    }

    /**
     * 读入CPL
     * 
     * @param root 根节点
     * @param model 当前模型
     */
    @SuppressWarnings("unchecked")
    private void readCPL(Element root, ReportModel model) {
        Element el = root.element("CPL");
        if (el != null) {
            List<Element> props = el.elements("Prop");
            for (int i = 0, size = props.size(); i < size; i++) {
                Element ele = props.get(i);
                model.setColumnWidth(i, NumberUtils.convertToInteger(ele.attributeValue("Width"), 0));
                model.setColumnType(i, Enum.valueOf(ColumnType.class, ele.attributeValue("Type")));
            }
        }
    }

    /**
     * 读入RPL
     * 
     * @param root 根节点
     * @param model 当前模型
     */
    @SuppressWarnings("unchecked")
    private void readRPL(Element root, ReportModel model) {
        Element el = root.element("RPL");
        if (el != null) {
            List<Element> props = el.elements("Prop");
            for (int i = 0, size = props.size(); i < size; i++) {
                Element ele = props.get(i);
                model.setRowHeight(i, NumberUtils.convertToInteger(ele.attributeValue("Height"), 0));
                model.setRowType(i, Enum.valueOf(RowType.class, ele.attributeValue("Type")));
            }
        }
    }

    /**
     * 读入报表配置
     * 
     * @param root 报表配置
     * @param model 模型
     */
    @SuppressWarnings("unchecked")
    private void readRS(Element root, ReportModel model) {
        ValueIOManager ioManager = ValueIOManager.INSTANCE;

        Element elRS = root.element("ReportSettings");
        if (elRS == null) {
            return;
        }

        Element elPaperSetting = elRS.element("PaperSetting");
        PaperSetting paperSetting = model.getReportSettings().getPaperSetting();

        Element elPaperSize = elPaperSetting.element("PaperSize");
        paperSetting.setPaperSize(PaperSize.getInstance(elPaperSize.attributeValue("Caption"), NumberUtils
                .convertToDouble(elPaperSize.attributeValue("Width"), 0.0D), NumberUtils.convertToDouble(elPaperSize
                .attributeValue("Height"), 0.0D)));

        Margin margin = paperSetting.getMargin();
        Element elMargin = elPaperSetting.element("Margin");

        margin.setTop(NumberUtils.convertToDouble(elMargin.attributeValue("Top"), 0.0D));
        margin.setLeft(NumberUtils.convertToDouble(elMargin.attributeValue("Left"), 0.0D));
        margin.setBottom(NumberUtils.convertToDouble(elMargin.attributeValue("Bottom"), 0.0D));
        margin.setRight(NumberUtils.convertToDouble(elMargin.attributeValue("Right"), 0.0D));

        paperSetting.setOrientation(NumberUtils.convertToInteger(elPaperSetting.elementText("Orientation"), 0));

        // 表头
        {
            Element elHeader = elRS.element("Header");
            ReportHF header = model.getReportSettings().getHeader();
            header.setHeight(NumberUtils.convertToDouble(elHeader.attributeValue("Height")));

            List<HFElement> lst = header.getLeftList();
            List<Element> elHFList = elHeader.element("Left").elements("Item");
            for (Element elHf : elHFList) {
                IValueIO io = ioManager.getValueIO(elHf.attributeValue("Clazz"));
                lst.add((HFElement) io.read(elHf));
            }

            lst = header.getCenterList();
            elHFList = elHeader.element("Center").elements("Item");
            for (Element elHf : elHFList) {
                IValueIO io = ioManager.getValueIO(elHf.attributeValue("Clazz"));
                lst.add((HFElement) io.read(elHf));
            }

            lst = header.getRightList();
            elHFList = elHeader.element("Right").elements("Item");
            for (Element elHf : elHFList) {
                IValueIO io = ioManager.getValueIO(elHf.attributeValue("Clazz"));
                lst.add((HFElement) io.read(elHf));
            }
        }

        // 表尾
        {
            Element elFooter = elRS.element("Footer");
            ReportHF footer = model.getReportSettings().getFooter();
            footer.setHeight(NumberUtils.convertToDouble(elFooter.attributeValue("Height")));

            List<HFElement> lst = footer.getLeftList();
            List<Element> elHFList = elFooter.element("Left").elements("Item");
            for (Element elHf : elHFList) {
                IValueIO io = ioManager.getValueIO(elHf.attributeValue("Clazz"));
                lst.add((HFElement) io.read(elHf));
            }

            lst = footer.getCenterList();
            elHFList = elFooter.element("Center").elements("Item");
            for (Element elHf : elHFList) {
                IValueIO io = ioManager.getValueIO(elHf.attributeValue("Clazz"));
                lst.add((HFElement) io.read(elHf));
            }

            lst = footer.getRightList();
            elHFList = elFooter.element("Right").elements("Item");
            for (Element elHf : elHFList) {
                IValueIO io = ioManager.getValueIO(elHf.attributeValue("Clazz"));
                lst.add((HFElement) io.read(elHf));
            }
        }
    }

    /**
     * 读取所有样式
     * 
     * @param root 所有样式
     */
    @SuppressWarnings("unchecked")
    private Map<String, Style> readStyle(Element root) {
        Map<String, Style> stylesMap = new HashMap<String, Style>();

        Element elStyles = root.element("Styles");
        List<Element> styles = elStyles.elements("Style");
        for (Element elStyle : styles) {
            Style style = Style.getInstance();
            TextStyle textStyle = Enum.valueOf(TextStyle.class, elStyle.elementText("TextStyle"));
            style = style.derivetTextStyle(textStyle);

            HorizentalAlignment hAlign = Enum.valueOf(HorizentalAlignment.class, elStyle
                    .elementText("HorizentalAlignment"));
            style = style.derivetHorizentalAlignment(hAlign);

            VerticalAlignment vAlign = Enum.valueOf(VerticalAlignment.class, elStyle.elementText("VerticalAlignment"));
            style = style.derivetVerticalAlignment(vAlign);

            BorderStyle borderStyle = BorderStyle.getInstance();
            Element elBorderStyle = elStyle.element("BorderStyle");
            borderStyle = borderStyle.applyBottomColor(ColorUtils.parseToColor(elBorderStyle
                    .attributeValue("BottomColor")));
            borderStyle = borderStyle.applyBottomStyle(NumberUtils.convertToInteger(elBorderStyle
                    .attributeValue("BottomStyle"), 0));
            borderStyle = borderStyle.applyHorizentalColor(ColorUtils.parseToColor(elBorderStyle
                    .attributeValue("HoriColor")));
            borderStyle = borderStyle.applyHorizentalStyle(NumberUtils.convertToInteger(elBorderStyle
                    .attributeValue("HoriStyle"), 0));
            borderStyle = borderStyle
                    .applyLeftColor(ColorUtils.parseToColor(elBorderStyle.attributeValue("LeftColor")));
            borderStyle = borderStyle.applyLeftStyle(NumberUtils.convertToInteger(elBorderStyle
                    .attributeValue("LeftStyle"), 0));
            borderStyle = borderStyle.applyRightColor(ColorUtils.parseToColor(elBorderStyle
                    .attributeValue("RightColor")));
            borderStyle = borderStyle.applyRightStyle(NumberUtils.convertToInteger(elBorderStyle
                    .attributeValue("RightStyle"), 0));
            borderStyle = borderStyle.applyTopColor(ColorUtils.parseToColor(elBorderStyle.attributeValue("TopColor")));
            borderStyle = borderStyle.applyTopStyle(NumberUtils.convertToInteger(elBorderStyle
                    .attributeValue("TopStyle"), 0));
            borderStyle = borderStyle.applyVerticalColor(ColorUtils.parseToColor(elBorderStyle
                    .attributeValue("VertColor")));
            borderStyle = borderStyle.applyVerticalStyle(NumberUtils.convertToInteger(elBorderStyle
                    .attributeValue("VertStyle"), 0));
            style = style.deriveBorder(borderStyle);

            Element elFontStyle = elStyle.element("FontStyle");
            FontStyle fontStyle = FontStyle.getInstance();
            fontStyle = fontStyle.applyName(elFontStyle.attributeValue("Name"));
            fontStyle = fontStyle.applyStyle(NumberUtils.convertToInteger(elFontStyle.attributeValue("Style"), 0));
            fontStyle = fontStyle.applySize(NumberUtils.convertToInteger(elFontStyle.attributeValue("Size"), 12));
            fontStyle = fontStyle.applyForeground(ColorUtils.parseToColor(elFontStyle.attributeValue("Foreground")));
            fontStyle = fontStyle.applyShadow(BooleanUtils.parseString(elFontStyle.attributeValue("Shadow")));
            fontStyle = fontStyle.applyStrikethrough(BooleanUtils.parseString(elFontStyle
                    .attributeValue("Strikethrough")));
            fontStyle = fontStyle.applySubscript(BooleanUtils.parseString(elFontStyle.attributeValue("Subscript")));
            fontStyle = fontStyle.applySuperscript(BooleanUtils.parseString(elFontStyle.attributeValue("Superscript")));
            fontStyle = fontStyle.applyUnderline(NumberUtils.convertToInteger(elFontStyle.attributeValue("Underline"),
                    0));

            style = style.deriveReportFont(fontStyle);
            style = style.deriveFormatterKey(elStyle.elementText("Format"));

            stylesMap.put(elStyle.attributeValue("Name"), style);
        }

        return stylesMap;
    }
}
